package cn.liufuwen.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * 继承WebMvcConfigureAdapter继承并重写addInterceptor方法用于添加配置拦截器
 */
@Configuration
public class MyWebMvcConfigurerAdapter extends WebMvcConfigurationSupport {
	@Override
    public void addInterceptors(InterceptorRegistry registry) {
		
	    
        registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/**") // addPathPatterns 用于添加拦截规则
                .excludePathPatterns("/hello/**", "/static/**"); // excludePathPatterns 用户排除拦截
    }
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //需要告知系统，这是要被当成静态文件的！
        //第一个方法设置访问路径前缀，第二个方法设置资源路径
        registry.addResourceHandler("/static/**")
        		.addResourceLocations("classpath:/static/");
	}
}
